// *** LICENSE HEADER ***
// Filename: ./particle.h
// This file is part of Nodewarz 0.1
// Nodewarz is a 3d OpenGL strategy game
// Copyright (C) 2007 CZestmyr
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// *** END LICENSE HEADER ***
#ifndef NODEWARS_PARTICLE_H
#define NODEWARS_PARTICLE_H

#include <GL/gl.h>
#include "affector.h"

class affector;

//Class, holding a single particle data
class particle {
    public:
        friend class particleEmitter;
        friend class gravityAffector;
        friend class flameAffector;
        friend class sphereRotationAffector;

        particle(float x, float y, float z,
                 float speedX = 0.0f, float speedY = 0.0f, float speedZ = 1.0f,
                 int lifetime = 5000, int fadeTime = 500, float newSize = 0.025f,
                 affector* newAff = 0, GLuint newTex = 0,
                 float newR = 1.0f, float newG = 1.0f, float newB = 0.4f,
                 float fR = 1.0f, float fG = 0.0f, float fB = 0.0f,
                 float newAlpha = 0.5f);
        //Set next particle in the linked-list
        void SetNext(particle* nextParticle);
        //Update this particle and move it, according to the current speed
        bool Update(int dt);
        //Draw the particle
        void Draw();

        //Set modelview matrix for all the particles
        static void SetModelviewMatrix();
    private:
        //Particle position
        float posX, posY, posZ;
        //Particle speed
        float speedX, speedY, speedZ;
        //Particle timing data
        int age, life, fadeout;
        //Particle size
        float size;
        //Particle color
        float r, g, b;
        //Particle fade color
        float fadeR, fadeG, fadeB;
        //Current color of the particle (used when drawing)
        float curR, curG, curB;
        //Alpha of the particle
        float alpha;
        float currentAlpha;
        //Particle affector
        affector* aff;
        //Particle texture
        GLuint texture;

        //Pointer to the next particle in the particel linked-list
        particle* next;

        static GLfloat modelview[16];
        static GLfloat transX;
        static GLfloat transY;
        static GLfloat transZ;
};

#endif
